package cn.db101.fairy.mapper

import cn.db101.fairy.entity.FairyDetail
import com.mybatisflex.core.BaseMapper
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update
import org.springframework.stereotype.Repository

@Repository
interface FairyDetailMapper: BaseMapper<FairyDetail> {

    /**
     * 查询前6查看数最多的童话故事
     */
    @Select("select * from t_fairy_detail order by views desc limit 6")
    fun findTop6Views(): List<FairyDetail>

    @Select("select * from t_fairy_detail order by collects desc limit 6")
    fun findTop6Collects(): List<FairyDetail>

    @Update("update t_fairy_detail set views = views + 1 where id = #{id}")
    fun addViews(id: Int)

    @Update("update t_fairy_detail set collects = collects + 1 where id = #{id}")
    fun addCollects(id: Int?)

    @Update("update t_fairy_detail set collects = collects - 1 where id = #{id}")
    fun delCollects(id: Int?)

}